from classify import Classifier
import sys
import jieba
import yaml
from classify import MySentences

if __name__ == '__main__':
    config_file = sys.argv[1]
    in_dir = sys.argv[2]
    out_file = sys.argv[3]

    conf = yaml.load(open(config_file, 'r'))
    classifiers = conf['classifiers']

    out_fd = open(out_file, 'w+')

    cv_file = classifiers['car_filter']['cv']
    tfidf_file = classifiers['car_filter']['tfidf']
    lg_file = classifiers['car_filter']['lg']

    clf = Classifier(cv_file, tfidf_file, lg_file)

    data_iter = MySentences(in_dir)
    for l in data_iter:
        t = l.strip()
        d = t.split('\t', 1)
        if len(d) != 3:
            continue
        pid = d[0].strip()
        # title_content = d[1] + d[2]
        seg = jieba.lcut(d[1] + d[2])
        out = clf.classify(seg)
        c = out[0][0]
        if c == 'not_car':
            out_fd.write(pid + '\n')
    out_fd.close()
